package com.star.truffle.shop.controller;

import javax.validation.constraints.NotNull;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.star.framework.autoconfigure.HnServiceException;
import com.star.framework.autoconfigure.web.BaseResult;
import com.star.truffle.shop.constants.ErrorCodeEnum;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Validated
@Tag(name = "测试")
@RestController

public class TestController {
  
  @RequestMapping(method = RequestMethod.POST, value = "/api/test")
  @Operation(method = "POST", summary = "测试")
  public BaseResult<String> test(@Parameter(description = "头部信息，用户id") @RequestHeader(name = "userId", required = false) Long userId, @Parameter(description = "供应Id", required = true) @RequestParam @NotNull(message = "supplyId 必填") Long supplyId) {
    try {
      return BaseResult.success(userId + supplyId + "");
    } catch (HnServiceException e) {
      return BaseResult.fail(e.getCode(), e.getMsg());
    } catch (Throwable e) {
      log.error(e.getMessage(), e);
      return BaseResult.fail(ErrorCodeEnum.SYSTEM_ERROR.getCode(), ErrorCodeEnum.SYSTEM_ERROR.getMsg());
    }
  }
  
  @RequestMapping(method = RequestMethod.POST, value = "/api/test2")
  @Operation(method = "POST", summary = "测试")
  public BaseResult<String> test2(@Parameter(description = "头部信息，用户id") @RequestHeader(name = "userId", required = false) Long userId, @Parameter(description = "供应Id", required = true) @RequestParam @NotNull(message = "supplyId 必填") Long supplyId) {
    try {
      return BaseResult.success(userId + supplyId + "");
    } catch (HnServiceException e) {
      return BaseResult.fail(e.getCode(), e.getMsg());
    } catch (Throwable e) {
      log.error(e.getMessage(), e);
      return BaseResult.fail(ErrorCodeEnum.SYSTEM_ERROR.getCode(), ErrorCodeEnum.SYSTEM_ERROR.getMsg());
    }
  }
  
  @RequestMapping(method = RequestMethod.POST, value = "/api/test3")
  @Operation(method = "POST", summary = "测试")
  public BaseResult<String> test3(@Parameter(description = "头部信息，用户id") @RequestHeader(name = "userId", required = false) Long userId, @Parameter(description = "供应Id", required = true) @RequestParam @NotNull(message = "supplyId 必填") Long supplyId) {
    try {
      return BaseResult.success(userId + supplyId + "");
    } catch (HnServiceException e) {
      return BaseResult.fail(e.getCode(), e.getMsg());
    } catch (Throwable e) {
      log.error(e.getMessage(), e);
      return BaseResult.fail(ErrorCodeEnum.SYSTEM_ERROR.getCode(), ErrorCodeEnum.SYSTEM_ERROR.getMsg());
    }
  }
}
